package com.charity.mapper;

import com.charity.pojo.Donation;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DonationMapper {

    @Select("select donorName,SUM(donationAmount) donationAmount from donation where MONTH(createDate)=#{month} GROUP BY donorName ORDER BY donationAmount desc limit 50")
    List<Donation> bangDan(Integer month);

    @Insert("insert into donation(id, donorId, donorName, donationAmount, entryId, createDate, state, stateM) " +
            "values(#{id}, #{donorId}, #{donorName}, #{donationAmount}, #{entryId}, #{createDate}, #{state}, #{stateM})")
    Integer addDonation(Long id, Long donorId, String donorName, Long donationAmount, Long entryId, String createDate, String state, String stateM);

    @Select("SELECT * from donation where id=#{id}")
    Donation selById(Long id);

    @Select("SELECT * from donation where donorId=#{donorId}")
    List<Donation> selByDonorId(Long donorId);

    @Select("SELECT * from donation where state='审核中'")
    List<Donation> selBySH();

    @Select("SELECT * from donation where state='通过' or stateM='已发放'")
    List<Donation> selQ();

    @Update("UPDATE donation set state=#{state},reviewer=#{reviewer} where id=#{id}")
    Integer updSh(Long id, String state, String reviewer);

    @Select("SELECT * from donation where state='不通过'")
    List<Donation> selWTG();

    @Delete("delete from donation where id=#{id}")
    Integer delD(Long id);

    @Update("UPDATE donation set account=#{account}, stateM='已发放' where entryId=#{entryId}")
    Integer updBC(Long entryId, String account);

    @Update("UPDATE donation set account=#{account}, stateM='已发放' where id=#{id}")
    Integer upFF(Long id, String account);
}
